manual nix upgrade

2024-12-15 · 1 min read

(For a multi-user Linux/macOS install)

By default, sudo nix upgrade-nix will grab the new nix version from your nixpkgs flake registry entry, which should work for most people. If instead you need to install a specific nix daemon version...

Start by looking at the current system default profile:

$ nix profile history --profile /nix/var/nix/profiles/default
Version 1 (2024-08-03):
  nix: -> 2.18.5
  nss-cacert: -> 3.83

Version 2 (2024-11-03) <- 1: # <<< this is our current version
  nix: 2.18.5 -> 2.24.9

$ nix profile list --profile /nix/var/nix/profiles/default
Name:               nix
Store paths:        /nix/store/2nhrwv91g6ycpyxvhmvc0xs8p92wp4bk-nix-2.24.9

Name:               nss-cacert
Store paths:        /nix/store/ba4f8msp39cfvfpw3m7fsalb4psw347z-nss-cacert-3.83

Install the new nix version. In this case, I'm installing nixVersions.latest from a local nixpkgs checkout:

$ cd ~/dev/nixpkgs
$ nix eval -f . nixVersions.latest.version
"nix-2.28.3"

# hold on to the current nix path while we're upgrading
$ NIX_BIN="$(readlink -f "$(which nix)")"

# pre-emptively build/fetch the new nix/cacert packages
$ nix build -f . pkgs.nixVersions.latest pkgs.cacert --print-out-paths

# remove the old nix+cacert packages
$ sudo $NIX_BIN profile remove \
    --profile /nix/var/nix/profiles/default \
    nix nss-cacert

# install the new nix+cacert packages
$ sudo $NIX_BIN profile install \
    --profile /nix/var/nix/profiles/default \
    -f . pkgs.nixVersions.latest pkgs.cacert

Reload the nix daemon:

# linux
$ sudo systemctl daemon-reload \
    && sudo systemctl restart nix-daemon

# macOS
$ sudo launchctl kickstart -k system/org.nixos.nix-daemon

Sanity check:

$ nix --version
nix (Nix) 2.28.3

$ nix store info
Store URL: daemon
Version: 2.28.3
Trusted: 0

If something goes horribly wrong, you can always rollback:

$ sudo $NIX_BIN profile rollback \
    --profile /nix/var/nix/profiles/default

If anything, you'll probably want to rollback before your next "normal" sudo nix upgrade-nix to keep things simple in the future.

Once everything's working, you can also garbage collect the old nix version(s):

$ sudo $(which nix) profile wipe-history \
    --profile /nix/var/nix/profiles/default
removing profile version 1
removing profile version 2

$ nix profile history \
    --profile /nix/var/nix/profiles/default
Version 3 (2025-06-26) <- 1:
  nix: -> 2.28.4
  nss-cacert: -> 3.98